
package com.feib.soeasy.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.feib.soeasy.model.FormatDefinition;
import com.feib.soeasy.model.Group;
import com.feib.soeasy.model.Payment;
import com.feib.soeasy.model.UploadFile;
import com.feib.soeasy.model.User;
import com.feib.soeasy.model.WriteOffPayment;
import com.feib.soeasy.pagination.PaginatedList;


/**
 * @title (#)PaymentService.java<br>
 * @description 繳費單邏輯介面<br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/18 create by Jimmy Liu<br>
 */
@Transactional(readOnly = true)
public interface PaymentService 
{
    @Transactional(readOnly = false)
    public void doWriteOffPayments(Payment payment);
    
    /**
     * 多筆核銷
     * @param payment
     * @param writeOffReason 核銷理由
     * @param writeOffNo 核銷代號
     * @return
     */
    @Transactional(readOnly = false)
    public void doWriteOffPayments(List<Payment> payment, String paymentWriteOffReason, String paymentWriteOffCode);
    
    @Transactional(readOnly = false)
    public void updatePayment(Payment payment);

    /**
     * 依uploadfile pk 值整批更新繳費狀態
     * @param paymentStatus
     * @param uploadFile
     */
    @Transactional(readOnly = false)
    public void updatePaymentStatusByUploadFile(UploadFile uploadFile);

    /**
     * 取得檔案應繳總金額
     * @param uploadFilePk      上傳檔案檔pk 值
     * @return 總金額
     * @author Leo Lee
     */
    public Long getTotalAmountByUploadFilePk(Long uploadFilePk);

    /**
     * 取得檔案應該總筆數
     * @param uploadFilePk 上傳檔案檔pk 值
     * @return 總筆數, 若回傳為 0 則查無應繳筆數
     * @author Leo Lee
     */
    public Long getCountItemByUploadFilePk(Long uploadFilePk);

    /**
     * 依據查詢物件與繳費截止日期起迄查詢繳費單
     * @param payment 查詢條件
     * @param payDueFrom 繳費截止日期起
     * @param payDueTo 繳費截止日期迄
     * @param paginationConfig 換頁條件
     * @return 查詢結果物件
     */
    public PaginatedList<Payment> queryByPayment(Payment payment, Date payDueFrom, Date payDueTo, PaginatedList<Payment> paginationConfig);

    public PaginatedList<Payment> queryByPayment(Payment payment, Date payDueFrom, Date payDueTo, PaginatedList<Payment> paginationConfig, String queryType);

    /**
     * 依paymentPk 取回單筆 Payment 檔
     * @param payment
     * @return
     */
    public Payment getPaymentByPk(Payment payment);

    public Payment getPaymentReport(Payment payment);

    /**
     * 查出此uploadfilepk 所有相關的paymentpk
     * @param uploadFilePk
     * @return
     */
    public List<Long> queryPaymentPkByUploadFilePk(Long uploadFilePk);


    public List<Payment> queryByPaymentStatus3(Payment payment, PaginatedList<Payment> paginationConfig);
    public List<Payment> queryByPaymentStatus2(Payment payment, PaginatedList<Payment> paginationConfig);
    
    @Transactional(readOnly = false)
    public void updatePaymentStatus(ArrayList<Payment> payment,String status);
    
    @Transactional(readOnly = false)
    public void updateWriteOffPaymentStatus(ArrayList<Payment> payment,String status);

    /**
     * TODO JEFF 需註銷
     * @param qryGroup
     * @param qryPayDueFrom
     * @param qryPayDueTo
     * @param qryVirtualAccountFrom
     * @param qryVirtualAccountTo
     * @return
     */
    public List<String> queryDownloadPayments(Group qryGroup,
                    Date qryPayDueFrom, Date qryPayDueTo, 
                    String qryVirtualAccountFrom, String qryVirtualAccountTo);

    /**
     * @param uploadFile
     * @param modifyUser 更新人員
     */
    @Transactional(readOnly = false)
    void updatePaymentStatusByUploadFile(UploadFile uploadFile, User modifyUser);

    /**
     * 單筆人工註銷
     * @param payment
     * @param cancelReason 註銷理由
     * @return
     */
    @Transactional(readOnly = false)
    public Payment doPaymentCanceled(Payment payment, String cancelReason);
    
    /**
     * 多筆註銷
     * @param payment
     * @param cancelReason 註銷理由
     * @param cancelNo 註銷代號
     * @return
     */
    @Transactional(readOnly = false)
    public List<Payment> doPaymentListCanceled(List<Payment> payment, String cancelReason, String cancelNo);
    
    public List<Payment> queryPaymentForDetailDownload(
                        UploadFile uploadFile, Integer paymentStatus);

    /**
     * 上傳檔案定義已轉入資料筆數
     * @param formatDefinitionPk
     * @return
     */
    public int countByFormatDefinitionPk(Long formatDefinitionPk);
    
    @Transactional(readOnly = false)
    public void batchUpdatePaymentStatusByUploadFile(
    		List<UploadFile> uploadFiles, User modifyUser, Integer fileStatus);

    /**
     * @param payment 查詢條件
     * @param formatDefinition 收款類別
     * @param payDueFrom 繳費期限起
     * @param payDueTo 繳費期限迄
     * @param writeOffDateFrom 繳費交易日期起
     * @param writeOffDateTo 繳費交易日期迄
     * @param paginationConfig 分頁、排序條件
     * @return
     */
    public PaginatedList<Payment> queryByPayment(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo, PaginatedList<Payment> paginationConfig);

    /**
     * @param payment 查詢條件
     * @param formatDefinition 收款類別
     * @param payDueFrom 繳費期限起
     * @param payDueTo 繳費期限迄
     * @param writeOffDateFrom 繳費交易日期起
     * @param writeOffDateTo 繳費交易日期迄
     * @param paginationConfig 分頁、排序條件
     * @return
     */
    public PaginatedList<Payment> queryByPaymentSql(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo, PaginatedList<Payment> paginationConfig);
    
    /**
     * @param checkPayment
     */
    @Transactional(readOnly = false)
    public void doNoticeUnPayByEmail(List<Payment> checkPayment);

    /**
     * @param cancelNo
     * @param b
     * @return
     */
    public Payment getPaymentByVirtualAccount(String virtualAccount, boolean unPay);

    /**
     * @param writeOffPayment
     */
    @Transactional(readOnly = false)
    public void doWriteOffPaymentsOnLine(WriteOffPayment writeOffPayment);
    //黃郁珊 依中租需求修改
    public List<String> queryPayerIdByUploadFilePk(Long uploadFilePk);
    public List<String> queryPaymentStatusByUploadFilePk(Long uploadFilePk);
    public List<Payment> queryPayementByPayerId(String payerId, Long uploadFilePk);
    
    public int getPaymentByGroup_type(String virtualAccount);
    
    
    public List<Payment> queryDownloadPayments(Payment payment,
            Date qryPayDueFrom, Date qryPayDueTo, 
            String qryVirtualAccountFrom, String qryVirtualAccountTo);

    
    /**
     * TODO 2012 10/1 JEFF
     * 查詢結果新增筆數與金額統計
     * @author Jeff Gu
     * @param payment 查詢條件
     * @param payDueFrom 繳費截止日期起
     * @param payDueTo 繳費截止日期迄
     * @param paginationConfig 換頁條件
     *
     */
    public List<Map<String,Object>> querySumByPayment(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo);
    
    
    
    
    /**
     * TODO 2012 10/1 JEFF
     * 逾期查詢
     * @author Jeff Gu
     * @param payment 查詢條件
     * @param formatDefinition 收款類別
     * @param payDueFrom 繳費期限起
     * @param payDueTo 繳費期限迄
     * @param writeOffDateFrom 繳費交易日期起
     * @param writeOffDateTo 繳費交易日期迄
     * @param paginationConfig 分頁、排序條件
     * @param delayCount TODO
     * @return
     */
    public PaginatedList<Payment> queryDelayPaymentBySql(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo, PaginatedList<Payment> paginationConfig,boolean isSchool, int delayCount);
 
    
    /**
     * TODO 2012 10/1 JEFF
     * 逾期查詢
     * @author Jeff Gu
     * @param payment 查詢條件
     * @param formatDefinition 收款類別
     * @param payDueFrom 繳費期限起
     * @param payDueTo 繳費期限迄
     * @param writeOffDateFrom 繳費交易日期起
     * @param writeOffDateTo 繳費交易日期迄
     * @param delayCount TODO
     * @return
     */
    public List<Map<String,Object>> querySumDelayPayment(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo,boolean isSchool, int delayCount);

}



